var app = angular.module('smApp',[]);
app.controller('smController',function($scope,$http){


    $scope.getSemesters = function () {
        //获取学期列表
        $http({
            method: 'GET',
            url: 'weektable/getSemesters.do',
            data: $.param({}),
            headers: { 'Content-Type': 'application/x-www-form-urlencoded'}
        }).then(function successCallback(response) {
            console.log(response);
            $scope.semesters = response.data.semesters;
            console.log($scope.semesters);

        }, function errorCallback(response) {
            console.log("获取数据信息失败！");
        });
    };

    $scope.getSemesters();

    /*获取学期周次数据操作*/
    $scope.getWeeks = function () {
        $scope.semesterid = $("#semester-select").val();
        $http({
            method: 'POST',
            url: 'weektable/getWeektable.do',
            data: $.param({"semesterid":$scope.semesterid}),
            headers: { 'Content-Type': 'application/x-www-form-urlencoded'}
        }).then(function successCallback(response) {
            console.log(response);
            $scope.semester = response.data.semester;
            $scope.weeks = response.data.weeks;
            console.log($scope.semester);
            console.log($scope.weeks);

        }, function errorCallback(response) {
            console.log("获取学期周次数据失败！");
        });
    };

    $("#semester-select").change(function(){
        $scope.getWeeks();
    });

    /*删除学期周次数据操作*/
    $scope.deleteSemesterBtn = function () {
        if(confirm("确定删除该学期吗？")){
            $scope.semesterid = $("#semester-select").val();
            $http({
                method: 'POST',
                url: 'weektable/deleteSemeterAndWeeks.do',
                data: $.param({"sid":$scope.semesterid}),
                headers: { 'Content-Type': 'application/x-www-form-urlencoded'}
            }).then(function successCallback(response) {
                console.log(response);
                $scope.isSuccess = response.data.isSuccess;
                if ($scope.isSuccess==0){
                    alert("成功删除");
                    window.location.href = "/semestermsgUrl.do";
                }

            }, function errorCallback(response) {
                console.log("删除学期周次数据失败！");
            });
        }
    };


});